*/
class ParserCache {
private $mMemc;
- const try116cache = false; /* Only useful $wgParserCacheExpireTime after updating to 1.17 */
-
/**
* Get an instance of this object
*
}
/**
- * Used to provide a unique id for the PoolCounter.
+ * Generates a key for caching the given article considering
+ * the given parser options.
+ *
+ * @note Which parser options influence the cache key
+ * is controlled via ParserOutput::recordOption() or
+ * ParserOptions::addExtraKey().
+ *
+ * @note Used by Article to provide a unique id for the PoolCounter.
* It would be preferable to have this code in get()
* instead of having Article looking in our internals.
*
return false;
}
+ // $optionsKey->mUsedOptions is set by save() by calling ParserOutput::getUsedOptions()
$usedOptions = $optionsKey->mUsedOptions;
wfDebug( "Parser cache options found.\n" );
} else {
- if ( !$useOutdated && !self::try116cache ) {
+ if ( !$useOutdated ) {
return false;
}
$usedOptions = ParserOptions::legacyOptions();
}
$value = $this->mMemc->get( $parserOutputKey );
- if ( self::try116cache && !$value && strpos( $value, '*' ) !== -1 ) {
- wfDebug( "New format parser cache miss.\n" );
- $parserOutputKey = $this->getParserOutputKey( $article,
- $popts->optionsHash( ParserOptions::legacyOptions(), $article->getTitle() ) );
- $value = $this->mMemc->get( $parserOutputKey );
- }
if ( !$value ) {
wfDebug( "ParserOutput cache miss.\n" );
wfIncrStats( "pcache_miss_absent" );
/**
* @param ParserOutput $parserOutput
- * @param Article $article
+ * @param WikiPage $page
* @param ParserOptions $popts
* @param string $cacheTime Time when the cache was generated
*/
- public function save( $parserOutput, $article, $popts, $cacheTime = null ) {
+ public function save( $parserOutput, $page, $popts, $cacheTime = null ) {
$expire = $parserOutput->getCacheExpiry();
if ( $expire > 0 ) {
$cacheTime = $cacheTime ?: wfTimestampNow();
$optionsKey->setContainsOldMagic( $parserOutput->containsOldMagic() );
- $parserOutputKey = $this->getParserOutputKey( $article,
- $popts->optionsHash( $optionsKey->mUsedOptions, $article->getTitle() ) );
+ $parserOutputKey = $this->getParserOutputKey( $page,
+ $popts->optionsHash( $optionsKey->mUsedOptions, $page->getTitle() ) );
// Save the timestamp so that we don't have to load the revision row on view
- $parserOutput->setTimestamp( $article->getTimestamp() );
+ $parserOutput->setTimestamp( $page->getTimestamp() );
$parserOutput->mText .= "\n<!-- Saved in parser cache with key $parserOutputKey and timestamp $cacheTime\n -->\n";
wfDebug( "Saved in parser cache with key $parserOutputKey and timestamp $cacheTime\n" );
$this->mMemc->set( $parserOutputKey, $parserOutput, $expire );
// ...and its pointer
- $this->mMemc->set( $this->getOptionsKey( $article ), $optionsKey, $expire );
+ $this->mMemc->set( $this->getOptionsKey( $page ), $optionsKey, $expire );
} else {
wfDebug( "Parser output was marked as uncacheable and has not been saved.\n" );
}
const EDITSECTION_REGEX = '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#';
function __construct( $text = '', $languageLinks = array(), $categoryLinks = array(),
- $containsOldMagic = false, $titletext = '' )
- {
+ $containsOldMagic = false, $titletext = ''
+ ) {
$this->mText = $text;
$this->mLanguageLinks = $languageLinks;
$this->mCategories = $categoryLinks;
* @throws MWException if given invalid input
*/
function addInterwikiLink( $title ) {
- $prefix = $title->getInterwiki();
- if ( $prefix == '' ) {
+ if ( !$title->isExternal() ) {
throw new MWException( 'Non-interwiki link passed, internal parser error.' );
}
+ $prefix = $title->getInterwiki();
if ( !isset( $this->mInterwikiLinks[$prefix] ) ) {
$this->mInterwikiLinks[$prefix] = array();
}
}
/**
- * Callback passed by the Parser to the ParserOptions to keep track of which options are used.
- * @access private
+ * Tags a parser option for use in the cache key for this parser output.
+ * Registered as a watcher at ParserOptions::registerWatcher() by Parser::clearState().
+ *
+ * @see ParserCache::getKey
+ * @see ParserCache::save
+ * @see ParserOptions::addExtraKey
+ * @see ParserOptions::optionsHash
*/
- function recordOption( $option ) {
+ public function recordOption( $option ) {
$this->mAccessedOptions[$option] = true;
}